package cn.bbs.ba.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Random;

public class YanZhengMaUtil {

	/**
	 * @param strPhone
	 * @param strValue
	 * @return
	 */
	public static String sendTelValue(String strPhone, String strValue) {
		String strYanzhema = "";
		String content = strValue; 
		
		StringBuffer sb = new StringBuffer("http://http.c123.com/tx/?");

		sb.append("uid=94336");

		sb.append("&pwd=4F32D8FB1246018DB002BCA8294FAABC");

		sb.append("&mobile=" + strPhone);
		sb.append("&encode=utf8");
		try {
			sb.append("&content="+URLEncoder.encode(new String(content.getBytes(), "UTF-8")));
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		String inputline = "100";
//		return inputline;
		URL url;
		try {
			url = new URL(new String(sb.toString().getBytes(),"UTF-8"));
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();

			connection.setRequestMethod("POST");
			

			BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

			inputline = in.readLine();

			System.out.println(inputline);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return inputline;
	}
	
	/**
	 * @return
	 */
	public static String getCheckCode() {
		Random random = new Random();
		String sRand = "";
		for (int i = 0; i < 6; i++) {
			String rand = String.valueOf(random.nextInt(10));
			sRand += rand;
		}
		return sRand;
	}
}
